package com.example.wordpress;

import com.facebook.Session;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;

public class LoginActivity extends Activity {
	private LoginView loginView;
	private LoginController loginController;
	private Session.StatusCallback estadoCallback;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		loginView = new LoginView(this);
		loginController = new LoginController(this, loginView, savedInstanceState);
		estadoCallback = loginController.getStatusCallback();
        
        ((Button) findViewById(R.id.authButton)).setOnClickListener(loginController);
	}
	
    @Override
    public void onStart() {
        super.onStart();
        Session.getActiveSession().addCallback(estadoCallback);
    }

    @Override
    public void onStop() {
        super.onStop();
        Session.getActiveSession().removeCallback(estadoCallback);
    }
    
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
	}	
	
	@Override
    protected void onSaveInstanceState(Bundle estadoSalida) {
        super.onSaveInstanceState(estadoSalida);
        Session sesion = Session.getActiveSession();
        Session.saveSession(sesion, estadoSalida);
    }
}
